<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/8/17
 * Time: 13:57
 */

namespace app\models;

use yii\base\Model;
use Yii;
use \common\helps\tools;//使用工具类

class Table extends Model
{
    /**
     * 表名
     * @var string
     */
    protected $table = 'd_check_table';

    public static $d_table_detail = 'd_table_detail';


    /**
     * title 表单列
     * @return array|bool
     */
    public function tableLine(){
        $query = new \yii\db\Query();
        $line = $query->select(['id','content','pid','level','order'])->from(tools::databaseName().'.'.$this->table)->all();

        $result = tools::getTree($line);

        return $result;

    }


    /**
     * title 跟据child查询表单列
     * @param $child
     * @return array
     */
    public static function childLine($child)
    {
        $query = new \yii\db\Query();
        $session = $query->select(['id','content','pid','level','order','child_id'])->from(tools::databaseName().'.d_check_table')->where(['child_id'=>$child])->all();
        return $session;

    }


    /**
     * title 跟据child 删除表单
     * @param $child
     * @return array
     */
    public function detailChild($child)
    {
        if($child == 1){
            return 2;
        }

        $del = Yii::$app->db->createCommand()->delete(tools::databaseName().'.'.$this->table, "child_id = '$child'")->execute();
        return $del;

    }

    /**
     * title id查询 表单详情
     * @param $id
     * @return array
     */
    public static function tableDetail($id)
    {
        $query = new \yii\db\Query();
        $session = $query->select(['id','across','endlong','status','content','create_time','update_time','child_id'])->from(tools::databaseName().'.'.self::$d_table_detail)->where(['child_id'=>$id])->all();
        return $session;
    }







}